﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using Runda.CMS.Bll;
using Runda.CMS.Common.Utility;
using Runda.CMS.Common.Entity;

namespace Runda.CMS.Portal.ContractFollowUp
{
    public partial class Holiday_config_edit : BasePage
    {
        private SysDictionaryBll sysBll = new SysDictionaryBll();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                initForm();
            }
        }

        private void initForm()
        {
            if (Request.QueryString["Param"] != null && Request.QueryString["Param"] != "")
            {
                SysDictionaryEntity sysDicEntity = sysBll.Get<SysDictionaryEntity>(new Guid(Request.QueryString["Param"].ToString()));
                txtName.Text = sysDicEntity.Name;
                txtValue.Text = sysDicEntity.Code.ToString();
                txtparmGUID.Value = Request.QueryString["Param"].ToString();
            }
            else if (Request.QueryString["type"] != null && Request.QueryString["type"] != "")
            {
                txttype.Value = Request.QueryString["type"].ToString();
            }
        }

        private void save()
        {
            SysDictionaryEntity sysDicEntity;
            if (Request.QueryString["Param"] != null && Request.QueryString["Param"] != "")
            {
                sysDicEntity = sysBll.Get<SysDictionaryEntity>(new Guid(txtparmGUID.Value));
            }
            else
            {
                sysDicEntity = new SysDictionaryEntity();
                sysDicEntity.CreatedBy = CurrentUserID;
                sysDicEntity.CreatedOn = System.DateTime.Now;
                sysDicEntity.Type = System.Convert.ToInt32(txttype.Value);               
                sysDicEntity.Name = txtName.Text;                    
                sysDicEntity.Level = 1;
            }
            sysDicEntity.Code = txtValue.Text.Trim();
        
            sysBll.InsertOrUpdate(sysDicEntity);
        }

        protected void lnkbtnSaveAndClose_Click(object sender, EventArgs e)
        {
            save();
            ClientScript.RegisterStartupScript(this.GetType(), "save", "alert('保存成功');window.close();", true);
        }
    }
}
